package com.stenio.fancat.service.monitor;

import com.stenio.fancat.vo.BehaviorCommentsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 监听评论和点赞
 */
@Service
public class ServerMonitor {


    public void monitorComments(Socket socket){

        //BehaviorCommentsVO behaviorCommentsVO = new BehaviorCommentsVO();

        ServerSocket serverSocket = null;
        InputStream inputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            serverSocket = new ServerSocket();
            while (true) {
                socket = serverSocket.accept();
                inputStream = socket.getInputStream();
                inputStreamReader = new InputStreamReader(inputStream);
                bufferedReader = new BufferedReader(inputStreamReader);
                System.out.println(bufferedReader);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
                inputStreamReader.close();
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }


    }


    public String test(){
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return serverSocket.getInetAddress().toString();
    }

    public static void main(String[] args) {
        ServerMonitor serverMonitor= new ServerMonitor();
        System.out.println(serverMonitor.test());
    }


}
